package com.designpatterns.iterator.concreteiterator;

import com.designpatterns.iterator.aggregate.List;
import com.designpatterns.iterator.iterator.Iterator;

/**
 * IteratorImpl Class Implements Iterator Interface
 * 
 * @author Haiqi.Wang
 * @since 2013-6-9下午4:10:24
 */
public class IteratorImpl implements Iterator {

	private List list;
	private int index;

	public IteratorImpl(List list) {
		index = 0;
		this.list = list;
	}

	@Override
	public Object next() {
		Object obj = list.get(index);
		index ++;
		return obj;
	}

	@Override
	public void first() {
		index = 0;
	}

	@Override
	public void last() {
		index = list.getSize();
	}

	@Override
	public boolean hasNext() {
		return index < list.getSize();
	}

}
